package cn.tedu.basic;

import javax.swing.text.html.HTMLDocument;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

//测试 List接口的方法
public class Test4_List {
    public static void main(String[] args) {
        List<Integer> L=new ArrayList();
        //调用方法
        L.add(17);
        L.add(16);
        L.add(15);
        L.add(19);
        L.add(2,20);
        L.add(3,null);
        System.out.println(L);
        System.out.println( L.get(1));
        System.out.println(L.indexOf(2));
        System.out.println(L.lastIndexOf(18));
        System.out.println(L.listIterator());
        System.out.println(L.listIterator(2));
        List<Integer> L1 =new ArrayList();
        L1.add(15);L1.add(16);L1.add(18);L1.add(20);
        System.out.println(L.remove(1));
        System.out.println(new Integer(18));//移除18,18为引用类型
        L1.add(1,20);
        System.out.println(L.removeAll(L1));
        System.out.println(L.set(1,2));
        System.out.println(L.toArray());
        System.out.println(L.subList(2,3));
        //父类迭代1
        Iterator<Integer> It =L.iterator();
        while (It.hasNext()){
            Integer I =It.next();
            System.out.println(I);
        }
        //子类迭代2,正向
        ListIterator<Integer> Ii =L.listIterator();
        while (Ii.hasNext()){
            Integer In =Ii.next();
            System.out.println(In);
        }
        //子类逆向迭代
        while (Ii.hasPrevious()){
            Integer Int =Ii.previous();
            System.out.println(Int);
        }
        //3利用for循环
        for (int i = 0; i <L1.size() ; i++) {
            Integer in =L1.get(i);
            System.out.println(in);
        }
        //4增强for循环/foreach循环：语法：for（循环得到的数据类型  变量名 ：循环的容器）{}
        for (Integer ing : L1) {
            System.out.println(ing);
        }
        int[] a ={1,2,3,45,56,58,59,57,8,9,8,7,56,946,464,64,4,64,64,6,464,1,564,16,54646,};
        for (Integer b : a){
            System.out.println(b);

        }
    }
}
